<template>
    <base-list ref="shipmentCom"
             :condition="condition"
             :datas.sync="data"
             :pageSearch="pageSearch">
        <el-form :inline="true"
             :model="condition"
             class="search-form"
             slot="search"
             label-width="100px">
            <el-row>
                <el-col :span="8"
                        class="search-width6">
                    <el-form-item label="出库单号">
                        <el-input v-model="condition['search_LIKE_planNo']"
                                placeholder=""></el-input>
                        <!-- <auto-search-cargo-type-name @selectName="v=>condition['search_LIKE_cargoTypeName']=v"></auto-search-cargo-type-name> -->
                    </el-form-item>
                </el-col>
                <el-col :span="7"
                        class="search-width6">
                    <el-form-item label="出库方式">
                        <el-select v-model="condition['search_EQ_outWay']"
                                placeholder="请选择"
                                clearable
                                filterable>
                        <el-option v-for="[key, val] in _dictPreStatus"
                                    :key="key"
                                    :label="val"
                                    :value="key"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="7"
                        class="search-width6">
                    <el-form-item label="车牌号">
                        <el-input type="text"
                                v-model="condition['search_LIKE_carNo']"
                                placeholder="请输入内容"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-button type="primary"
                                icon="el-icon-search"
                                class="ml-100"
                                @click="loadData">查 询</el-button>
                    <el-button formVisible="true"
                                icon="el-icon-refresh"
                                @click="resuleBtn('aList')">
                        重置
                    </el-button>
                </el-col>
            </el-row>
        </el-form>
        
                <!-- show-summary -->
                <!-- :summary-method="getSummaries" -->
            <el-form :model="dispatchInfo"  slot="list">
                <el-table
                :data="data"
                border
                stripe
                max-height="550"
                @selection-change="handleSelectRow">
                    <el-table-column type="selection"
                                    width="50"
                                    align="center"></el-table-column>
                    <el-table-column prop="carNo"
                                    label="车号"
                                    width="120"></el-table-column>
                    <el-table-column prop="planNo"
                                    label="出库单号"
                                    width="100"></el-table-column>
                    <el-table-column prop="outWay"
                                    label="出库方式"
                                    width="100">
                                <template slot-scope="scope">
                                {{ scope.row.outWay | _filterOutWay}}
                                </template>    
                    </el-table-column>
                    <el-table-column prop="cargoOwnerName"
                                    label="货主"
                                    width="150"></el-table-column>
                    <el-table-column prop="deliveryBy"
                                    label="提货单位"
                                    width="100"></el-table-column>
                    <el-table-column prop="cargoName"
                                    label="品名"
                                    width="100"></el-table-column>
                    <el-table-column prop="normStr"
                                    label="规格"
                                    width="120"></el-table-column>
                    <el-table-column prop="material"
                                    label="材质"
                                    width="100">
                    </el-table-column>
                    <el-table-column prop="planNum"
                                    label="件数"
                                    width="180"></el-table-column>
                    <el-table-column prop="planWeight"
                                    label="重量"
                                    width="180"></el-table-column>
                    <el-table-column prop="expireTime"
                                    label="过期时间"
                                    width="180"></el-table-column>
                    <el-table-column prop="outStockNum"
                                    label="实际发运件数"
                                    width="100">
                        <template slot-scope="scope">
                            <el-input-number :controls="false"
                                v-model="scope.row.outStockNum"
                                size="small"></el-input-number>
                        </template>
                    </el-table-column>
                    <el-table-column prop="outStockWeight"
                                    label="实际发运重量"
                                    width="100">
                                    <template slot-scope="scope">
                                        <el-input-number :controls="false"
                                            v-model="scope.row.outStockWeight"
                                            size="small"></el-input-number>
                                    </template>
                                    </el-table-column>
                    <el-table-column prop="transportWay"
                                    label="运输方式"
                                    width="180">
                                    <template slot-scope="scope">
                                        <el-select v-model="scope.row.transportWay"
                                                placeholder="请选择"
                                                clearable>
                                        <el-option v-for="[key, val] in _dictTransportModeType"
                                                    :key="key"
                                                    :label="val"
                                                    :value="key"></el-option>
                                        </el-select>
                                    </template>
                                    </el-table-column>
                    <el-table-column prop="carNo"
                                    label="发运车船号"
                                    width="180">
                                    <template slot-scope="scope">
                                        <el-input :controls="false"
                                                v-model="scope.row.carNo"
                                                size="small"></el-input>
                                    </template>
                                    </el-table-column>
                </el-table>
                <el-row style="text-align:center;margin-top:10px">
                    <el-button type="primary" @click="handleSubmit" :loading="$store.getters.loadingBtn">发 运</el-button>
                </el-row>
            </el-form>
    </base-list>
</template>
<script>
import { getPcOutStockPlan } from '@/api/things/out'
import { batchShip } from '@/api/accept/carry'
export default {
    name: '',
    components: {},
    data() {
        return {
            form: this.clearForm(),
            dialogForm: false,
            data: [],
            component: '',
            condition: {}, // 查询条件
            pageSearch: getPcOutStockPlan, // 分页查询api接口
            "dispatchInfo": {}, //发运json
            selectRow: [] //选中行
        }
    },
    mounted() {
    },
    methods: {
        clearForm() {
            return {
                search_LIKE_planNo: '',
                search_EQ_outWay: '',
                search_LIKE_carNo: ''
            }
        },
        loadData() {
            this.$refs.shipmentCom.loadData()
        },
        handleSelectRow(val) {
            console.log(val)
            this.selectRow = val
        },
        handleSubmit() {
            // "dispatchCount": 0,
            //     "dispatchMode": 0,
            //     "dispatchNum": 0,
            //     "dispatchWeight": 0,
            //     "transhipNo": 0
            if(this.selectRow.length == 0) {
                this.$message({ message: '请选择一天数据!', type: 'error' })
                return false
            }else{
                var obj = {}, arr = []
                this.selectRow.forEach(e => { 
                    obj = {
                        dispatchInfo: {
                            dispatchCount: e.outStockCount,
                            dispatchMode: e.transportWay,
                            dispatchNum: e.outStockNum,
                            dispatchWeight: e.outStockWeight,
                            transhipNo: e.carNo
                        },
                        planNo: e.planNo
                    }
                    arr.push(obj)
                });
                console.log(arr)
                getPcOutStockPlan(arr).then(res => {
                    this.$message({ message: '分配成功!', type: 'success' })
                    this.$emit('load')
                })
            }
        }
    }
}
</script>

